package demo3;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/forward2")
public class ForwardServlet2 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 1. 获取转发的请求域数据
        String bizResult = (String) request.getAttribute("bizResult");
        Integer count = (Integer) request.getAttribute("count");

        // 2. 直接写响应（无工具类）
        response.setContentType("text/html;charset=utf-8");
        PrintWriter out = response.getWriter();
        out.write("<html><body>");
        out.write("<h3>请求转发接收页</h3>");
        out.write("<p>业务结果：" + bizResult + "</p>");
        out.write("<p>携带的数字：" + count + "</p>");
        out.write("<p>地址栏路径：" + request.getRequestURI() + "</p>");
        out.write("</body></html>");
        out.close();
    }
}
